package other.database;



import java.sql.*;


/**
 * @author bingo
 * @Description
 * @Date 2018/5/20
 */
public class DBUtil {


    public  static String username="root";

    public static  String password = "root";

    public static  String JDBC_URL="jdbc:mysql://127.0.0.1:3306/database-demo?useSSL=false";

    public static  String JDBC_DRIVER = "com.mysql.jdbc.Driver";

    private static  Connection connection;

    //3426
    //570
    public static Connection getConnection(){
        try {
            Class.forName(JDBC_DRIVER);
            connection = DriverManager.getConnection(JDBC_URL,username,password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  connection;
    }

    public static void releaseDB(ResultSet resultSet, Statement statement,
                                 Connection connection) {

        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        if (statement != null) {
            try {
                statement.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        if (connection != null) {
            try {
                connection.close();
                System.out.println("连接已经关闭");
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    public static void main(String[] args) {

       long startTime = System.currentTimeMillis();
        for(int i=0;i<10;i++){
            Connection connection = DBUtil.getConnection();
            DBUtil.releaseDB(null,null,connection);
        }
        long endTime = System.currentTimeMillis();
        System.out.println(endTime-startTime);

    }

}
